#-------------------------------------------------------------------------------
# Name:        Gui tut
# Purpose:     Provide an intro to GUI programming
#
# Author:      Jeff
#
# Created:     03/04/2013
# Copyright:   (c) Jeff 2013
# Licence:     GNU Public License
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import tkinter
#import tkinter, a GUI library

class simpleAppTk(tkinter.Tk):
    def __init__(self, parent):
        tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialize()

    def initialize(self):
        self.grid()
        #creates a grid layout, like an excel spreadsheet

        self.entryVariable=tkinter.StringVar()
        self.entry=tkinter.Entry(self, textvariable=self.entryVariable)
        self.entry.grid(column=0, row=0, sticky='EW')
        #creates the textbox and sets the location
        self.entry.bind("<Return>", self.OnPressEnter)
        self.entryVariable.set("Enter text here")

        button=tkinter.Button(self, text="Click me!",
                                command=self.OnButtonClick)
        button.grid(column=1 ,row=0)
        #creates the button and sets the location

        self.labelVariable=tkinter.StringVar()
        label=tkinter.Label(self, textvariable=self.labelVariable,
                            anchor='w', fg='white', bg='blue')
        #adds the label, sets foreground and background
        label.grid(column=0,row=1,columnspan=2,sticky='EW')
        #sets the label to span two columns, to show under the button and text box
        self.labelVariable.set("Hello!")

        self.grid_columnconfigure(0, weight=1)
        self.resizable(True, False)
        #allows the window to be resized horizontally, but not vertically
        self.update()
        self.geometry(self.geometry())
        #stops the window from auto resizing
        self.entry.focus_set()
        self.entry.selection_range(0, tkinter.END)
        #auto selects the text field

    def OnButtonClick(self):
            self.labelVariable.set(self.entryVariable.get())
            self.entry.focus_set()
            self.entry.selection_range(0, tkinter.END)

    def OnPressEnter(self,event):
            self.labelVariable.set(self.entryVariable.get())
            self.entry.focus_set()
            self.entry.selection_range(0, tkinter.END)

if __name__ == '__main__':
    app = simpleAppTk(None)
    app.title('My App')
    app.mainloop()
    #looping the application so it won't auto close


def main():
    pass
